{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bs4 import BeautifulSoup\n",
    "localtext = open('10.html', 'r', encoding='utf8')\n",
    "sp = BeautifulSoup(localtext, 'lxml')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<!DOCTYPE html>\n",
       "<html lang=\"en\">\n",
       "<head>\n",
       "<meta charset=\"utf-8\"/>\n",
       "<meta content=\"width=device-width, initial-scale=1.0\" name=\"viewport\"/>\n",
       "<meta content=\"ie=edge\" http-equiv=\"X-UA-Compatible\"/>\n",
       "<title>text和string</title>\n",
       "</head>\n",
       "<body>\n",
       "<div id=\"divid\">\n",
       "<p>p1</p>\n",
       "<p>p2</p>\n",
       "<p>p3</p>\n",
       "<p id=\"cp\">\n",
       "            cp1\n",
       "            <span>s1</span>\n",
       "            cp2\n",
       "            <span>s2</span>\n",
       "            cp3\n",
       "        </p>\n",
       "<a href=\"a1\">a1</a>\n",
       "<a href=\"a2\">a2</a>\n",
       "<a href=\"a3\">a3</a>\n",
       "</div>\n",
       "</body>\n",
       "</html>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'<!DOCTYPE html>\\n<html lang=\"en\">\\n <head>\\n  <meta charset=\"utf-8\"/>\\n  <meta content=\"width=device-width, initial-scale=1.0\" name=\"viewport\"/>\\n  <meta content=\"ie=edge\" http-equiv=\"X-UA-Compatible\"/>\\n  <title>\\n   text和string\\n  </title>\\n </head>\\n <body>\\n  <div id=\"divid\">\\n   <p>\\n    p1\\n   </p>\\n   <p>\\n    p2\\n   </p>\\n   <p>\\n    p3\\n   </p>\\n   <p id=\"cp\">\\n    cp1\\n    <span>\\n     s1\\n    </span>\\n    cp2\\n    <span>\\n     s2\\n    </span>\\n    cp3\\n   </p>\\n   <a href=\"a1\">\\n    a1\\n   </a>\\n   <a href=\"a2\">\\n    a2\\n   </a>\\n   <a href=\"a3\">\\n    a3\\n   </a>\\n  </div>\\n </body>\\n</html>'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sp.prettify()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<!DOCTYPE html>\n",
      "<html lang=\"en\">\n",
      " <head>\n",
      "  <meta charset=\"utf-8\"/>\n",
      "  <meta content=\"width=device-width, initial-scale=1.0\" name=\"viewport\"/>\n",
      "  <meta content=\"ie=edge\" http-equiv=\"X-UA-Compatible\"/>\n",
      "  <title>\n",
      "   text和string\n",
      "  </title>\n",
      " </head>\n",
      " <body>\n",
      "  <div id=\"divid\">\n",
      "   <p>\n",
      "    p1\n",
      "   </p>\n",
      "   <p>\n",
      "    p2\n",
      "   </p>\n",
      "   <p>\n",
      "    p3\n",
      "   </p>\n",
      "   <p id=\"cp\">\n",
      "    cp1\n",
      "    <span>\n",
      "     s1\n",
      "    </span>\n",
      "    cp2\n",
      "    <span>\n",
      "     s2\n",
      "    </span>\n",
      "    cp3\n",
      "   </p>\n",
      "   <a href=\"a1\">\n",
      "    a1\n",
      "   </a>\n",
      "   <a href=\"a2\">\n",
      "    a2\n",
      "   </a>\n",
      "   <a href=\"a3\">\n",
      "    a3\n",
      "   </a>\n",
      "  </div>\n",
      " </body>\n",
      "</html>\n"
     ]
    }
   ],
   "source": [
    "print(sp.prettify())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
